<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title></title>
        <link href="css/paginaPronta.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body onload="document.getElementById('form1:codigo').focus()" >
        <ui:composition template="#{mudarTemplateBean.template}">

            <ui:define name="centro">


                <!--h2><h:messages globalOnly="true" layout="table" showDetail="true" infoStyle="color: blue" warnStyle="color: yellow" errorStyle="color: red"/></h2-->
                <div id="divCentro">
                    <p:messages globalOnly="true" showDetail="true" redisplay="left" />
                    <p:panel header="#{mens.CADASTRO_DE_PRODUTOS}" visible="true" toggleable="true" styleClass="painelCentral" >
                        <h:form id="form1">
                            <h:inputHidden value="#{manterProdutoBean.produto.id}"/>
                            <!--p:inputText id="codigo" value="#{manterProdutoBean.codigo}" required="true" size="30">

                                    <f:validateRegex pattern="[0-9]+" for="codigo" />
                                    <f:validateLongRange minimum="1" maximum="999999999" for="codigo"/>
                                </p:inputText-->
                            <h:panelGrid  columns="3" >

                                <h:outputText value="#{mens.NOME}" />
                                <p:inputText id="nome" value="#{manterProdutoBean.produto.nome}" required="true" size="30" />
                                <p:message for="nome"/>

                                <h:outputText value="#{mens.CODIGO}" />
                                <p:keyboard clearLabel="Limpar" closeLabel="Fechar" backspaceLabel="Apagar" id="codigo" value="#{manterProdutoBean.codigo}" required="true" size="30" keypadOnly="true"/>

                                <p:message for="codigo"/>
                                <h:outputText value="#{mens.PRECO}" />
                                <p:inputText id="preco" required="true" value="#{manterProdutoBean.preco}" size="30" >
                                    <f:validateRegex pattern="[0-9]+[.][0-9]+" for="preco" />
                                    <f:validateDoubleRange minimum="0.01" maximum="99999.99" for="preco"/>
                                </p:inputText>
                                <p:message for="preco"/>
                              </h:panelGrid>
                             <p:separator />

                            <h:panelGrid cellspacing="5" columns="3">
                                <h:commandButton value="#{mens.INSERIR}" action="#{manterProdutoBean.create}" />
                                <h:commandButton value="#{mens.ALTERAR}" action="#{manterProdutoBean.edit}" disabled="#{manterProdutoBean.naoSelecionouProduto}"/>
                                <h:commandButton value="#{mens.EXCLUIR}" action="#{manterProdutoBean.destroy}" disabled="#{manterProdutoBean.naoSelecionouProduto}"/>
                            </h:panelGrid>
                        </h:form>

                        <h:form>
                            <h:panelGrid >
                                <p:panel header="#{mens.PESQUISAR_POR}" >
                                    <h:selectOneMenu >
                                        <f:selectItem itemLabel=""/>
                                        <f:selectItem itemLabel="Nome"/>
                                        <f:selectItem itemLabel="Codigo"/>

                                    </h:selectOneMenu>
                                    <p:inputText  style="margin-left: 5px"/>
                                    <p:commandButton  value="#{mens.PESQUISAR}" action="#{manterProdutoBean.findProdutoEntities}" image="url(../img/pesquisa2.png)" ajax="false" />
                                </p:panel>
                            </h:panelGrid>
                        </h:form>

                    </p:panel>
                    <h:form>
                        <div >
                            <p:panel header="#{mens.PAINEL_DE_PESQUISA}" visible="true" toggleable="true" styleClass="painelCentral">
                                <p:dataTable styleClass="fonteTabela" emptyMessage="#{mens.TABELA_VAZIA}"  paginator="true" rows="5" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} " rowsPerPageTemplate="5"  value="#{manterProdutoBean.produtos}" var="p" rendered="#{manterProdutoBean.exibeTabela}">

                                    <p:column style="width: 10px; overflow: auto; text-align: left">
                                        <f:facet name="header">#{mens.CODIGO}</f:facet>

                                        <h:commandLink style="color: maroon; font-weight: bolder" value="#{p.codigo}" action="paginaManterProdutoTeste.xhtml">
                                            <f:setPropertyActionListener value="#{p.codigo}" target="#{manterProdutoBean.codigo}"/>
                                            <f:setPropertyActionListener value="#{p.nome}" target="#{manterProdutoBean.produto.nome}"/>
                                            <f:setPropertyActionListener value="#{p.preco}" target="#{manterProdutoBean.preco}"/>
                                            <f:setPropertyActionListener value="#{p.id}" target="#{manterProdutoBean.produto.id}"/>
                                            <f:setPropertyActionListener value="false" target="#{manterProdutoBean.naoSelecionouProduto}"/>
                                        </h:commandLink>


                                    </p:column>

                                    <p:column styleClass="ui-column">
                                        <f:facet  name="header">#{mens.NOME}</f:facet>
                                        <h:outputText value="#{p.nome}"/>
                                    </p:column>
                                    <p:column styleClass="ui-column">
                                        <f:facet name="header">#{mens.PRECO}</f:facet>
                                        <h:outputText value="#{p.preco}"/>
                                    </p:column>
                                </p:dataTable>
                            </p:panel>
                        </div>
                    </h:form>
                </div>
            </ui:define>
        </ui:composition>



    </h:body>
</html>
